home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Palette.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  19.2 KB  |  557 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Palette.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.0.6+>    11/19/93    NAGA        modify TCS format
  19. #     <1.0.6>     8/25/93    KTA        Added support for parity checking the TCS stack.
  20. #     <1.0.5>      8/3/93    KTA        SelFromCoord() - There was no returnVal for absolute coordinate
  21. #                                    moves.
  22. #     <1.0.4>      6/8/93    NAGA        unmark tasks that are not published
  23. #     <1.0.3>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  24. #
  25. # ****************************************************************************
  26. #
  27.  
  28. ########################################################################
  29. #                            External libraries 
  30. #=======================================================================
  31. Libraries  "TCS.Lib","Output.Lib","UserInterface.Lib";
  32.  
  33. #########################################################################
  34. #########################################################################
  35. #                            Palette Structure Accessors()
  36. #========================================================================
  37. # Author:        DM (x41220)
  38. # Description:    These functions access the data in an palette data struct
  39. # Parameters:    palStruct
  40. # Returns:        the requested data element or list
  41. #========================================================================
  42. # History:
  43. #
  44. #########################################################################
  45. task GetPalRect(palStruct)         begin return( palStruct[1] );    end;
  46. task GetPalType(palStruct)         begin return( palStruct[2] );    end;
  47. task GetPalMatrixSize(palStruct) begin return( palStruct[3] );    end;
  48. task GetPalOffsets(palStruct)     begin return( palStruct[4] );    end;
  49. #task GetPalHeaderSize(palStruct) begin return( palStruct[5] );    end;    # Not used
  50. #task GetPalOnDesk(palStruct)         begin return( palStruct[6] );    end;    # Not used
  51.  
  52. task InsertPalRect(rect, pS)        begin return( replace(rect, 1, pS ));    end;
  53. task InsertPalOnDesk(onDesk, pS)    begin return( replace(onDesk, 6, pS ));end;
  54.  
  55.  
  56. #########################################################################
  57. #                            Tool Structure Accessors()
  58. #========================================================================
  59. # Author:        DM (x41220)
  60. # Description:    These functions access the data in an tool data struct
  61. # Parameters:    elemStruct
  62. # Returns:        the requested data element or list
  63. #========================================================================
  64. # History:
  65. #
  66. #########################################################################
  67. ## elemStruct is the data structure that completely specifies tools
  68. ##            elemStruct    {
  69. ##                ElemNum
  70. ##                PalNum
  71. ##                ElemName
  72. ##                ElemType    - kClick := move-click 
  73. ##                                        (Pointlist is single set of points)
  74. ##                            - kDrag     := move-pressmouse-move-releasMouse 
  75. ##                                        (Pointlist is two set of points)
  76. ##                            == Pointlist is defined by Global gNumPoints ==
  77. ##                            - kMultiDrag := move-pressmouse-move-move…releasMouse
  78. ##                            - kMultiClick:= move-click-move-click-move…
  79. ##                            - kMultiClickDragTool := move-pressmouse-move-releasMouse-pressmouse-move-releasMouse…
  80. ##                            
  81. ##                elemDblClk  - Flag to doulble click when finished
  82. ##                            - 0 := No DoubleClick
  83. ##                            - 1 := DoubleClick
  84. ##
  85. ##                SetAttribute  - Flag indicating when to set attributes
  86. ##                            - 0 := No attributes to set
  87. ##                            - 1 := Set attribute before drawing object
  88. ##                            - 2 := Set attribute after drawing object
  89. ##                            - "str" := Type <'Str'> after drawing object (texttool)
  90. ##            }
  91. ##        Defined ElemTypes:
  92. ##                 
  93. #########################################################################
  94. ##    Example: global CharTool    :=     { ElemNum, PalNum,"ElemName", ElemType,    elemDblClk};
  95. ##             global CharTool    :=     { 17     , 1     ,"Char"    , kClick  ,    0          };
  96. #########################################################################
  97. task GetElemNum(elemStruct)         begin return( elemStruct[1] );    end;
  98. task GetPalNum(elemStruct)             begin return( elemStruct[2] );    end;
  99. task GetElemName(elemStruct)        begin return( elemStruct[3] );    end;
  100. task GetElemType(elemStruct)         begin return( elemStruct[4] );    end;
  101. task GetElemDblClk(elemStruct)        begin return( elemStruct[5] );    end;
  102.  
  103. task GetAttributes(elemStruct)        begin return( elemStruct[6] );    end;
  104. task GetSetAttribute(elemStruct)    begin return( elemStruct[6][1] );    end;
  105. task GetPatternFlag(elemStruct)        begin return( elemStruct[6][2] );    end;
  106. task GetLineFlag(elemStruct)        begin return( elemStruct[6][3] );    end;
  107. task GetColorFlag(elemStruct)        begin return( elemStruct[6][4] );    end;
  108.  
  109. task InsertElemNum(eNum, tS)         begin return( replace( eNum, 1, tS ));    end;
  110. task InsertPalNum(pNum, tS)         begin return( replace( pNum, 2, tS ));    end;
  111. task InsertElemName(eNam, tS)        begin return( replace( eNam, 3, tS ));    end;
  112. task InsertElemType(eTyp, tS)         begin return( replace( eTyp, 4, tS ));    end;
  113. task InsertElemDblClk(eDbc, tS)        begin return( replace( eDbc, 5, tS ));    end;
  114. task InsertSetAttribute(eDbc, tS)    begin return( replace( eDbc, 6, tS ));    end;
  115.  
  116. #########################################################################
  117. #                    PalettePicker(elemStruct) 
  118. #========================================================================
  119. # Author:            DM
  120. # Description:        Dispatches selection request to palette handlers.  
  121. # Parameters:        elemStruct:= Structure containing element info
  122. #                                         Only the first 3 elements are required.
  123. #                            kInWindPal := 1;
  124. #                            kIsWindPal := 2;
  125. #                            kPullOffPal:= 3;
  126. #                            kPopUpPal := 4;
  127. #                            kScrollPal := 5;
  128. #
  129. # Return Values:    1 -  OK
  130. #                        0 - error
  131. # Examples:            PalettePicker(elemStruct);
  132. #========================================================================
  133. # History:
  134. # KTA    8/24/93        TCS stack parity check
  135. #########################################################################
  136. TASK PalettePicker(elemStruct := {}, ObjectNumber := 0) begin
  137.     if (global gDebugFlag)
  138.         Println "----- PalettePicker() - Palette.lib --------";
  139.     global kPalDocWind, kPalWind, kPullOffPal, kPopUpPal, kScrollPal, kDebugLog;
  140.     global gPaletteList;
  141.     
  142.     thePalNum := GetPalNum(elemStruct);            # get the palette number
  143.     #### Handle Direct Coordinate Tools #####
  144.     if (TypeOF(thePalNum) = 'list')
  145.     begin
  146.         returnVal := SelFromCoord(elemStruct,ObjectNumber);    # no palette only coordinates
  147.         if (returnVal)
  148.             returnVal := elemStruct;
  149.     end;
  150.     else
  151.     begin
  152.         theElemName := GetElemName(elemStruct);        # get the elem name
  153.         theElemNum :=     GetElemNum(elemStruct);            # get the elem number
  154.         thePalette := gPaletteList[thePalNum];        # get the palette
  155.         thePalType := GetPalType(thePalette);            # get the palette type
  156.         theElemNum := "{theElemNum}";                        # Num to String
  157.         myPal := "{thePalNum}";
  158.         if(Card(theElemNum) = 1)                            # if its a single digit add a zero
  159.             theElemNum := "0" + theElemNum;
  160.         TCSNum := "{myPal}" + "{theElemNum}";
  161.         TCSNum := StrToNum( TCSNum );
  162.         TCSStart({ TCSNum, global kTCSetPalettePicker },"PalettePicker");        # Start TCS
  163.         
  164.         LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette #{thePalNum}",4);
  165.         if (thePalType = kPalDocWind)
  166.                 returnVal := SelFromDocWind(elemStruct);
  167.                 else if (thePalType = kPalWind) 
  168.                     returnVal := SelFromPalWind(elemStruct);
  169.                     else if (thePalType = kPullOffPal)
  170.                         returnVal := SelFromPullOff(elemStruct);
  171.                         else if (thePalType = kPopUpPal) begin
  172.                                 returnVal := SelFromPopUp(elemStruct);
  173.                             end;
  174.                             else if (thePalType = kScrollPal)
  175.                                 returnVal := SelFromScroll(elemStruct);
  176.                                 else begin
  177.                                     LogStr("No selection function declared for palette type {thePalType}",2);
  178.                                     returnVal := 0;
  179.                                 end;
  180.         TCSEnd({ TCSNum, global kTCSetPalettePicker }, returnVal,,ObjectNumber,theElemName);
  181.     end; 
  182.     return(returnVal);        #Return what sub routines return
  183. end;    
  184.     
  185.     
  186. #########################################################################
  187. #                    CalcOffset(elemStruct) 
  188. #========================================================================
  189. # Author:            KTA
  190. # Description:        Calculates tool offsets based on palette info.  
  191. # Parameters:        elemStruct:= structure containing element info
  192. # Return Values:    toolOffset:= {x,y}
  193. #                        0 - error
  194. # Examples:            CalcOffset(elemStruct);
  195. #========================================================================
  196. # History:
  197. #
  198. #########################################################################
  199. task CalcOffset(elemStruct)
  200. begin
  201.     global gPaletteList, kPopUpPal, kDebugLog;
  202.  
  203.     #LogStr("Calculating tool offset");
  204.     thePalNum := GetPalNum(elemStruct);
  205.     thePalette := gPaletteList[thePalNum];
  206.     thePalType := GetPalType(thePalette);
  207.     elemNum := GetElemNum(elemStruct);
  208.     theRect := GetPalRect(thePalette);
  209.     theOffsets := GetPalOffsets(thePalette);
  210.     theMatrix := GetPalMatrixSize(thePalette);
  211.     headerHeight := 0;
  212.  
  213.     xOffset := theOffsets[1];
  214.     yOffset := theOffsets[2];
  215.     elemsAcross := theMatrix[1];
  216.     elemsDown := theMatrix[2];
  217.  
  218.     if ((Card(theRect) = 1) or (Card(theRect) = 2))    # kPalWind
  219.     begin                                # be a seperate palette window
  220.         if (theRect[2])
  221.             headerHeight := theRect[2];
  222.         
  223.         theWindow := Findwindow(theRect[1]);
  224.         if (TheWindow)
  225.             theRect := TheWindow.r;
  226.     end;
  227.     
  228.     if ((elemNum <= elemsAcross) and (elemsAcross > 1))
  229.     begin
  230.         xMove := elemNum * xOffset;
  231.         #Println "xMove1 - ", xmove;
  232.     end;
  233.     else 
  234.     begin
  235.         if ((elemNum mod elemsAcross) <> 0)
  236.         begin
  237.             xMove := ((elemNum mod elemsAcross)) * xOffset;
  238.             #Println "xMove2 - ", xmove;
  239.         end;
  240.         else
  241.         begin
  242.             if (elemsAcross = 1)        # Fix to handle palettes with only 1 column of tools
  243.             begin
  244.                 xMove := (theRect[1]+theRect[3])/2;
  245.                 #Println "xMove3 - ", xmove;
  246.             end;
  247.             else
  248.             begin
  249.                 xMove := ((elemsAcross)) * xOffset;
  250.                 #Println "xMove4 - ", xmove;
  251.             end;
  252.         end;
  253.     end;
  254.     if (elemNum mod elemsAcross = 0) and (yOffset <> 0)
  255.     begin
  256.         yMove := (elemNum/elemsAcross) * yOffset;
  257.         #Println "yMove1 - ", ymove;
  258.     end;
  259.     else
  260.     begin
  261.         if (elemsDown = 1)    # Fix to handle palettes with only 1 row of tools
  262.         begin
  263.             yMove := (theRect[2]+theRect[4])/2 - (theRect[2] + headerHeight);
  264.             #Println "yMove2 - ", ymove;
  265.         end;
  266.         else
  267.         begin
  268.             yMove := (elemNum/elemsAcross +1) * yOffset;
  269.             #Println "yMove3 - ", ymove;
  270.         end;
  271.     end;
  272.     xAbsoluteOffSet := theRect[1];
  273.     yAbsoluteOffSet := theRect[2] + headerHeight;
  274.  
  275.     if (thePalType = kPopUpPal)    #To handle popup palettes when selecting from a 
  276.     begin                                    # palette you begin at the correct location.
  277.         xAbsoluteOffSet := 0;
  278.         yAbsoluteOffSet := 0;
  279.     end;
  280.     if (elemsAcross = 1)
  281.         xAbsoluteOffSet := 0;
  282.         
  283.     xMove := xMove + xAbsoluteOffSet - xOffset/2;
  284.     yMove := yMove + yAbsoluteOffSet - yOffset/2;
  285.     If((xMove) or (yMove))
  286.         returnVal := {xMove, yMove};
  287.     else
  288.         returnVal := 0;
  289.     #Println "This is the CalcOffset returnVal - ", returnVal;
  290.     return(returnVal);
  291. end; # CalcOffset()
  292.  
  293. #########################################################################
  294. #                    SelFromDocWind(elemStruct) 
  295. #========================================================================
  296. # Author:            DM
  297. # Description:        Selects tools from palettes that are builtin to doc windows.  
  298. #                        You can also specify a Rect in Global coordinates outside
  299. #                        the document window. 
  300. # Parameters:        elemStruct
  301. # Return Values:    1 -  OK
  302. #                        0 - error
  303. # Examples:            SelFromDocWind(elemStruct);
  304. #========================================================================
  305. # History:
  306. #
  307. #########################################################################
  308. TASK SelFromDocWind(elemStruct)
  309. begin
  310.     global gPaletteList;
  311.     windSpecifier := 0;
  312.     thePalNum := GetPalNum(elemStruct);
  313.     thePalette := gPaletteList[thePalNum];
  314.     theRect := GetPalRect(thePalette);
  315.     
  316.     LogStr("Selecting from a palette that in a doc window");
  317.  
  318.     whereMove := CalcOffset(elemStruct);
  319.     if(whereMove)
  320.     begin
  321.         xMove := whereMove[1];
  322.         yMove := whereMove[2];
  323.         temp := global gDisableAllLogging;
  324.         if not(global gDebugFlag)
  325.             gDisableAllLogging := 1;
  326.         if (Card(theRect) = 4) 
  327.             MoveMouse(xMove, yMove, 1,    2); # Select Tool/Absolute Coordinates
  328.         else if(Card(theRect) = 5)
  329.         begin
  330.             windSpecifier := theRect[5];
  331.             MoveRelativeToWindow(xMove, yMove, windSpecifier,    2); # Select Tool/Relative to doc window
  332.         end;
  333.         gDisableAllLogging := temp;
  334.         returnVal := 1;
  335.     end;
  336.     else
  337.         returnVal := 0;
  338.     
  339.     return(returnVal);
  340. end;
  341. #########################################################################
  342. #                    SelFromPalWind(elemStruct) 
  343. #========================================================================
  344. # Author:            DM
  345. # Description:        Selects tools from palettes that are windows.  
  346. # Parameters:        elemStruct:= structure containing element info
  347. # Return Values:    1 -  OK
  348. #                        0 - error
  349. # Examples:            SelFromPalWind(elemStruct);
  350. #========================================================================
  351. # History:
  352. #
  353. #########################################################################
  354. TASK SelFromPalWind(elemStruct)
  355. begin
  356.     LogStr("Selecting from a palette that is in a separate window");
  357.     returnVal := 0;
  358.  
  359.     whereMove := CalcOffset(elemStruct);
  360.     if(whereMove)
  361.     begin
  362.         xMove := whereMove[1];
  363.         yMove := whereMove[2];
  364.         temp := global gDisableAllLogging;
  365.         if not(global gDebugFlag)
  366.             gDisableAllLogging := 1;
  367.         MoveMouse(xMove, yMove, ,    2);    # Select tool
  368.         gDisableAllLogging := temp;
  369.         returnVal := 1;
  370.     end;
  371.     else
  372.         returnVal := 0;
  373.     
  374.     return(returnVal);
  375. end;
  376. #########################################################################
  377. #                    SelFromPullOff(elemStruct) 
  378. #========================================================================
  379. # Author:            DM
  380. # Description:        Selects tools from palettes that tear off menu bar.  
  381. # Parameters:        elemStruct:= structure containing tool info
  382. # Return Values:    1 -  OK
  383. #                        0 - error
  384. # Examples:            SelFromPullOff(elemStruct);
  385. #========================================================================
  386. # History:
  387. #
  388. #########################################################################
  389. TASK SelFromPullOff(elemStruct)
  390. begin
  391.     if (global gDebugFlag)
  392.         Println "----- SelFromPullOff() - Palette.lib --------";
  393.     LogStr("Selecting from a palette that pulls off");
  394.  
  395. end;
  396. #########################################################################
  397. #                    SelFromCoord(elemStruct, ObjectNumber) 
  398. #========================================================================
  399. # Author:            KTA
  400. # Description:        Selects tools from coodinates either global or relative to the 
  401. #                        front window.
  402. # Parameters:        elemStruct:= structure containing tool info
  403. # Return Values:    Returns what is returned by MoveRelativeToWindow() or MoveMouse()
  404. # Examples:            SelFromCoord(elemStruct);
  405. #========================================================================
  406. # History:
  407. # KTA    8/3/93        There was no returnVal for absolute coordinate moves.
  408. # KTA    8/24/93        TCS stack parity check
  409. #########################################################################
  410. TASK SelFromCoord(elemStruct,ObjectNumber)
  411. begin
  412.     temp := global gDisableAllLogging;
  413.     if not(global gDebugFlag)
  414.         gDisableAllLogging := 1;
  415.  
  416.     theElemName := GetElemName(elemStruct);    # get the elem name
  417.     theCoord := GetPalNum(elemStruct);            # get the palette number
  418.     theElemNum := GetElemNum(elemStruct);            # get the elem number
  419.         xCoor := theCoord[1];
  420.         yCoor := theCoord[2];
  421.         RelativeFlag := theCoord[3];
  422.  
  423.  
  424.         TCSNum := theElemNum;
  425.         TCSStart({ TCSNum, global kTCSetToolPalette },"SelectFromCoord");        # Start TCS
  426.  
  427.         Str := "Selecting the '{theElemName}' tool from coordinates ∂({xCoor},{yCoor}∂)";
  428.         if (RelativeFlag) # RelativeToWindow
  429.         begin
  430.             returnVal := MoveRelativeToWindow(xCoor, yCoor, ,2,,RelativeFlag);
  431.             str1:= " which are relative to the front window";
  432.         end;
  433.         else    # Absolute Coordinates 
  434.         begin
  435.             MoveMouse(xCoor, yCoor, , 2);
  436.             returnVal:= 1;
  437.             str1:= " which are absolute coordinates";
  438.         end;
  439.         # Tool has been Selected
  440.         
  441.         Str := Str + str1;
  442.         gDisableAllLogging := temp;
  443.         LogStr(Str);
  444.         if (returnVal)
  445.             TCSReturn :=1;
  446.         else
  447.             TCSReturn :=0;
  448.         TCSEnd({ TCSNum, global kTCSetToolPalette }, TCSReturn,,ObjectNumber,theElemName);
  449.         
  450.         return(returnVal);
  451. end;
  452. #########################################################################
  453. #                    SelFromPopUp(elemStruct) 
  454. #========================================================================
  455. # Author:            DM
  456. # Description:        Selects tools from palettes that pop up.  
  457. # Parameters:        elemStruct:= structure containing element info
  458. # Return Values:    1 -  OK
  459. #                        0 - error
  460. # Examples:            SelFromPopUp(elemStruct);
  461. #========================================================================
  462. # History:
  463. #
  464. #########################################################################
  465. TASK SelFromPopUp(elemStruct)
  466. begin
  467.     windSpecifier := 0;
  468.     global gPaletteList, kDebugLog, gAppVerify;
  469.     thePalNum := GetPalNum(elemStruct);
  470.     thePalette := gPaletteList[thePalNum];
  471.     theRect := GetPalRect(thePalette);
  472.     if (global gDebugFlag)
  473.         println "This is the ElemStruct", elemStruct;
  474.     # if we are moving with absolute coordinates the rect should have 4 items
  475.     if (Card(theRect) = 4)
  476.         AbsoluteCoord := 1;
  477.     else if (Card(theRect) = 5)        # IF 
  478.         windSpecifier := theRect[5];
  479.  
  480.     whereMove := CalcOffset(elemStruct);
  481.     if(whereMove)
  482.     begin
  483.         xMove := whereMove[1];
  484.         yMove := whereMove[2];
  485.         returnVal := 1;
  486.     end;
  487.     else
  488.         returnVal := 0;
  489.  
  490.     tempSpeed := MouseSpeed(5);
  491.     temp := global gDisableAllLogging;
  492.     if not(global gDebugFlag)
  493.         gDisableAllLogging := 1;
  494.  
  495.     if (AbsoluteCoord)
  496.         MoveMouse(theRect[1], theRect[2], 1,    0);      # move to pop-point
  497.     else
  498.         MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier,    0);      # move to pop-point
  499.     
  500.     tempAppVerify := gAppVerify;
  501.     gAppVerify := 0;
  502.     PressMouse;
  503.     wait(2);
  504.     MoveMouse(theRect[3] - theRect[1], theRect[4] - theRect[2], 0,    0);    # press mouse - move to topLeft item
  505.     MoveMouse(xMove, yMove, 0,    0);                # move to item and release
  506.     ReleaseMouse;
  507.     gAppVerify := tempAppVerify;
  508.     gDisableAllLogging := temp;
  509.     MouseSpeed(tempSpeed);
  510.  
  511.     return(returnVal);
  512. end;
  513. #########################################################################
  514. #                    SelFromScroll(elemStruct) 
  515. #========================================================================
  516. # Author:            DM
  517. # Description:        Selects elements from palettes that are builtin to doc windows.  
  518. # Parameters:        elemStruct:= structure containing element info
  519. # Return Values:    1 -  OK
  520. #                        0 - error
  521. # Examples:            SelFromScroll(elemStruct);
  522. #========================================================================
  523. # History:
  524. #
  525. #########################################################################
  526. TASK SelFromScroll(elemStruct)
  527. begin
  528.     if (global gDebugFlag)
  529.         Println "----- SelFromScroll() - Palette.lib --------";
  530.     LogStr("Selecting from a palette that scrolls");
  531.  
  532. end;
  533.  
  534. #########################################################################
  535. #                        GetRandomElement()
  536. #========================================================================
  537. # Author:        DM (x41220)
  538. # Description:    
  539. # Parameters:    palStruct
  540. # Returns:        
  541. #========================================================================
  542. # History:
  543. #
  544. #########################################################################
  545. TASK GetRandomElement(palStruct) begin
  546.     if (global gDebugFlag)
  547.         Println "----- GetRandomElement() - Palette.lib --------";
  548.     global kDebugLog;
  549.     theMatrix := GetPalMatrixSize(palStruct);
  550.     numCells := theMatrix[1]*theMatrix[2];
  551.     
  552.     elemNum := random(1, numCells);
  553.     return elemNum;
  554. end; # GetRandomElement()
  555.  
  556.  
  557.